package com.codinghero.zqlb.spider.handler;

import java.sql.SQLException;
import java.util.List;

import com.codinghero.sql.DBOper;
import com.codinghero.sql.MySQLOper;
import com.codinghero.zqlb.Constant;
import com.codinghero.zqlb.match.SoccerMatch;

@Deprecated
public class UpdateMatchTimeHandler implements MatchHandler {

	public <T extends SoccerMatch> void handle(List<T> list) {
		DBOper dbOper = new MySQLOper(Constant.JDBC_URL, Constant.USER_ID, Constant.PASSWORD);
		try {
			dbOper.connect();
			dbOper.startTransaction();
			dbOper.addBatch("UPDATE zqlb_soccer_match m, zqlb_soccer_match_temp t SET m.startDate=t.startDate " +
					" WHERE m.typeId=t.typeId AND m.team1Id=t.team1Id AND m.team2Id=t.team2Id AND m.startDate!=t.startDate " +
					" AND (( TIMEDIFF(m.startDate, t.startDate)<'32:00:00' AND TIMEDIFF(m.startDate, t.startDate)>'00:00:00' ) " +
					" OR ( TIMEDIFF(t.startDate, m.startDate)<'32:00:00' AND TIMEDIFF(t.startDate, m.startDate)>'00:00:00' ))");

			dbOper.addBatch("UPDATE zqlb_soccer_match m, zqlb_soccer_match_temp t " +
					" SET m.channelIds=t.channelIds, m.channelNames=t.channelNames " +
					" WHERE m.typeId=t.typeId AND m.team1Id=t.team1Id AND m.team2Id=t.team2Id " +
					" AND (m.channelIds!=t.channelIds OR m.channelNames!=t.channelNames )");
			int[] affectedNums = dbOper.executeBatch();
			dbOper.commit();
			System.out.println("更新了" + affectedNums[0] + "个比赛的时间");
			System.out.println("更新了" + affectedNums[1] + "个比赛的转播频道");
		} catch (SQLException e) {
			dbOper.rollback();
			e.printStackTrace();
		} finally {
			dbOper.close();
		}
	}

}
